package actions;

import utils.Constants;
import client_gui.ClientWindow;

/**
 * Klasa koja predstavlja menadzera svih akcija. U ovoj klasi se kreiraju sve akcije i
 * rukuje se pravima i dozvolama nad pojedinim akcijama u zavisnosti od rezima rada
 * GUI aplikacije.
 * 
 * @author UrosKrkic & Radivoje Popovic
 */
public class RLMActionManager implements Constants {
	
	/**
	 * Vlasnik akcije (action owner).
	 */
	private ClientWindow owner;
	
	
	private HelpAction helpAction;
	private AboutAction aboutAction;
	private SendFileAction sendFileAction;
	private SendMessageAction sendMessageAction;
	private DeleteUserAction deleteUserAction;
	private BlockUserAction blockUserAction;;
	private UnblockUserAction unblockUserAction;
	private DetailsUserAction detailsUserAction;
	private LogoutAction logoutAction;
	private FindUserAction findUserAction;
	private OptionsAction optionsAction;
	private ExitAction exitAction;
	private AlwaysOnTopAcition alwaysOnTopAction;
	private ChangePasswordAction changePasswordAction;
	private UnregisterAction unregisterAction;
	private BlockListAction blockListAction;
	private LoginAction loginAction;
	private ChangeStatusAction changeStatusAction;
	private DefaultPositionAndSizeAction defaultPositionAndSize;
	private ChangeEmailAction changeEmailAction;
	private MyDetailsAction myDetailsAction;
	private SplashScreenAction splashScreenAction;
	private AudioCallAction audioCallAction;
	private VideoCallAction videoCallAction;
	private StopCallAction stopCallAction;
	private StreamingSettingsAction streamingSettingsAction;

	
	/**
	 * Konstruktor.
	 * @param owner - vlasnik akcije
	 * @author UrosKrkic & Radivoje Popovic
	 */
	public RLMActionManager(ClientWindow owner) {
		this.owner = owner;
		initializeActions();
	}
	
	
	private void initializeActions() {
		helpAction = new HelpAction(owner);
		aboutAction = new AboutAction(owner);
		sendFileAction = new SendFileAction(owner);
		sendMessageAction = new SendMessageAction(owner);
		deleteUserAction = new DeleteUserAction(owner);
		blockUserAction = new BlockUserAction(owner);
		unblockUserAction = new UnblockUserAction(owner);
		detailsUserAction = new DetailsUserAction(owner);
		logoutAction = new LogoutAction(owner);
		findUserAction = new FindUserAction(owner);
		optionsAction = new OptionsAction(owner);
		exitAction = new ExitAction(owner);
		alwaysOnTopAction = new AlwaysOnTopAcition(owner);
		changePasswordAction = new ChangePasswordAction(owner);
		unregisterAction = new UnregisterAction(owner);
		blockListAction = new BlockListAction(owner);
		loginAction = new LoginAction(owner);
		changeStatusAction = new ChangeStatusAction(owner);
		defaultPositionAndSize = new DefaultPositionAndSizeAction(owner);
		changeEmailAction = new ChangeEmailAction(owner);
		myDetailsAction = new MyDetailsAction(owner);
		splashScreenAction = new SplashScreenAction(owner);
		audioCallAction = new AudioCallAction(owner);
		videoCallAction = new VideoCallAction(owner);
		stopCallAction = new StopCallAction(owner);
		streamingSettingsAction = new StreamingSettingsAction(owner);
		
		// setovanje prava i dozvola
		setRights();
	}
	
	
	/**
	 * Metoda setuje prava i dozvole za pojedine akcije u zavisnosti od rezima rada
	 * GUI aplikacije.
	 * @author UrosKrkic & Radivoje Popovic
	 */
	public void setRights() {
		switch ( owner.getApplicaton().getState() ) {
		
			case INITIAL_STATE:
				logoutAction.setEnabled(false);
				sendMessageAction.setEnabled(false);
				sendFileAction.setEnabled(false);
				audioCallAction.setEnabled(false);
				videoCallAction.setEnabled(false);
				stopCallAction.setEnabled(false);
				deleteUserAction.setEnabled(false);
				blockUserAction.setEnabled(false);
				unblockUserAction.setEnabled(false);
				findUserAction.setEnabled(false);
				detailsUserAction.setEnabled(false);
				changePasswordAction.setEnabled(false);
				unregisterAction.setEnabled(false);
				blockListAction.setEnabled(false);
				changeEmailAction.setEnabled(false);
				myDetailsAction.setEnabled(false);
				break;
				
			case LOGGED_STATE:
				logoutAction.setEnabled(true);
				sendMessageAction.setEnabled(false);
				sendFileAction.setEnabled(false);
				audioCallAction.setEnabled(false);
				videoCallAction.setEnabled(false);
				stopCallAction.setEnabled(false);
				deleteUserAction.setEnabled(false);
				blockUserAction.setEnabled(false);
				unblockUserAction.setEnabled(false);
				findUserAction.setEnabled(true);
				detailsUserAction.setEnabled(false);
				changePasswordAction.setEnabled(true);
				unregisterAction.setEnabled(true);
				blockListAction.setEnabled(true);
				changeEmailAction.setEnabled(true);
				myDetailsAction.setEnabled(true);
				break;
		}
	}
	
	
	/**
	 * Metod setuje prava za Block i Unblock akciju u zavisnosti od flag-a koji
	 * oznacava da li je korisnik blokiran ili nije.
	 * Ukoliko je korisnik blokiran, onemogucava se akcija blokiranja, a dozvoljava
	 * se akcija deblokiranja, i suprotno.
	 * @param flag - true, ako je korisnik blokira, inace false
	 * @author UrosKrkic & Radivoje Popovic
	 */
	public void setBlockedRights(boolean flag) {
		if (flag == true) {
			blockUserAction.setEnabled(false);
			unblockUserAction.setEnabled(true);
		}
		else {
			blockUserAction.setEnabled(true);
			unblockUserAction.setEnabled(false);
		}
	}
	
	
	/**
	 * Setuje prava na send akciju.
	 * @param flag
	 * @author UrosKrkic & Radivoje Popovic
	 */
	public void setSendRights(boolean flag) {
		if (flag == false) {
			sendMessageAction.setEnabled(false);
			sendFileAction.setEnabled(false);
			audioCallAction.setEnabled(false);
			videoCallAction.setEnabled(false);
			stopCallAction.setEnabled(false);
		}
		else {
			sendMessageAction.setEnabled(true);
			sendFileAction.setEnabled(true);
			audioCallAction.setEnabled(true);
			videoCallAction.setEnabled(true);
			stopCallAction.setEnabled(true);
		}
	}
	
	
	/**
	 * Metod setuje prava za akcije iz menija Actions, ukoliko se selektuje cvor Online
	 * ili Offline, odnosno, zabranjuju se stavke iz Actions menija ukoliko su selektovani
	 * ovi cvorovi.
	 * @param flag - true, ako se vrsi zabrane, false, ako se ponistava zabrana
	 * @author UrosKrkic & Radivoje Popovic
	 */
	public void setOnOffLineRights(boolean flag) {
		if (flag == true) {
			sendMessageAction.setEnabled(false);
			sendFileAction.setEnabled(false);
			audioCallAction.setEnabled(false);
			videoCallAction.setEnabled(false);
			stopCallAction.setEnabled(false);
			deleteUserAction.setEnabled(false);
			blockUserAction.setEnabled(false);
			unblockUserAction.setEnabled(false);
			detailsUserAction.setEnabled(false);
		}
		else {
			sendMessageAction.setEnabled(true);
			sendFileAction.setEnabled(true);
			audioCallAction.setEnabled(true);
			videoCallAction.setEnabled(true);
			stopCallAction.setEnabled(true);
			deleteUserAction.setEnabled(true);
			blockUserAction.setEnabled(true);
			unblockUserAction.setEnabled(true);
			detailsUserAction.setEnabled(true);
		}
	}
	
	
	/**
	 * Metod vraca referencu na HelpAction objekat.
	 * @return - HelpAction objekat
	 * @author UrosKrkic & Radivoje Popovic
	 */
	public HelpAction getHelpAction() {
		return helpAction;
	}
	
	
	/**
	 * Metod vraca referencu na AboutAction objekat.
	 * @return - AboutAction objekat
	 * @author UrosKrkic & Radivoje Popovic
	 */
	public AboutAction getAboutAction() {
		return aboutAction;
	}
	


	public BlockUserAction getBlockUserAction() {
		return blockUserAction;
	}
	
	
	public UnblockUserAction getUnblockUserAction() {
		return unblockUserAction;
	}


	public DeleteUserAction getDeleteUserAction() {
		return deleteUserAction;
	}


	public DetailsUserAction getDetailsUserAction() {
		return detailsUserAction;
	}


	public FindUserAction getFindUserAction() {
		return findUserAction;
	}


	public LogoutAction getLogoutAction() {
		return logoutAction;
	}


	public OptionsAction getOptionsAction() {
		return optionsAction;
	}


	public StreamingSettingsAction getStreamingSettingsAction() {
		return streamingSettingsAction;
	}
	
	
	public SendFileAction getSendFileAction() {
		return sendFileAction;
	}


	public SendMessageAction getSendMessageAction() {
		return sendMessageAction;
	}


	public ExitAction getExitAction() {
		return exitAction;
	}


	public AlwaysOnTopAcition getAlwaysOnTopAction() {
		return alwaysOnTopAction;
	}


	public ChangePasswordAction getChangePasswordAction() {
		return changePasswordAction;
	}


	public UnregisterAction getUnregisterAction() {
		return unregisterAction;
	}


	public BlockListAction getBlockListAction() {
		return blockListAction;
	}


	public LoginAction getLoginAction() {
		return loginAction;
	}


	public ChangeStatusAction getChangeStatusAction() {
		return changeStatusAction;
	}


	public DefaultPositionAndSizeAction getDefaultPositionAndSize() {
		return defaultPositionAndSize;
	}


	public ChangeEmailAction getChangeEmailAction() {
		return changeEmailAction;
	}


	public MyDetailsAction getMyDetailsAction() {
		return myDetailsAction;
	}


	public SplashScreenAction getSplashScreenAction() {
		return splashScreenAction;
	}


	public AudioCallAction getAudioCallAction() {
		return audioCallAction;
	}


	public VideoCallAction getVideoCallAction() {
		return videoCallAction;
	}


	public StopCallAction getStopCallAction() {
		return stopCallAction;
	}
	
}
